import assert from "node:assert/strict";
import { parse } from "jsonc-morph";

const root = parse(`{
  // 1
  "data" /* 2 */: 123 // 3
} // 4`);

// get the root object
const rootObj = root.asObjectOrThrow();

console.log(rootObj.data);

// set its "data" property to have a new value
rootObj.getOrThrow("data").setValue({
  nested: true,
});

// append a new key
rootObj.append("new_key", [456, 789, false]);

// inspect the output
assert.equal(
  root.toString(),
  `{
  // 1
  "data" /* 2 */: {
    "nested": true
  }, // 3
  "new_key": [456, 789, false]
} // 4`,
);
